/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bm.main.threading;

import com.bm.util.MessagePrinter;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *
 * @author ssm
 */
public class TerminateApp implements Runnable {

    @Override
    public void run() {
        while (true) {
            checkTerminateApp();
            try {
                Thread.sleep(120000);
            } catch (InterruptedException ex) {
                MessagePrinter.printDebug(ex.getMessage());
            }
        }
    }

    public static void checkTerminateApp() {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sd = new SimpleDateFormat("HH");
        int hour = Integer.valueOf(sd.format(c.getTime()));
        sd = new SimpleDateFormat("mm");
        int minute = Integer.valueOf(sd.format(c.getTime()));
        if (hour == 23 && minute >= 55) {
            System.exit(1);
        } else {
            MessagePrinter.printDebug("Application terminated on 23:55. Current Time: " + hour + ":" + minute);
        }
    }
}
